﻿@using System.Data;
@using DTcms.Model;
@using DTcms.Common;
@{
   Layout = "~/Areas/admin/Views/Shared/_LayoutEdit.cshtml";
   ViewBag.Title = "编辑频道";
   DTcms.Model.site_channel m = ViewData["model"] as DTcms.Model.site_channel;
   List<DTcms.Model.url_rewrite> urlList = ViewData["urlList"] as List<DTcms.Model.url_rewrite>;
   List<SelectListItem> siteList = ViewData["siteListItems"] as List<SelectListItem>;
   DataTable fieldList = ViewData["fieldList"] as DataTable;
}
@section HeaderContent{
<script>
   $(function () {
      //初始化表单验证
      $("#form1").initValidform();
      //添加按钮(点击绑定)
      $("#itemAddButton").click(function () {
         showChannelDialog();
      });
      //关联规格相关字段
      var objMarketPrice;
      var objSellPrice;
      var objStockQuantity; //声明对象
      $("#cblAttributeField input").each(function () {
         var fieldArr = $(this).val().split(',');
         var fieldIndex = $("#cblAttributeField input").index($(this));
         if (fieldArr[0] == 'market_price') {
            objMarketPrice = $("#cblAttributeField").siblings("ul").children("li").eq(fieldIndex).children("a");
         }
         if (fieldArr[0] == 'sell_price') {
            objSellPrice = $("#cblAttributeField").siblings("ul").children("li").eq(fieldIndex).children("a");
         }
         if (fieldArr[0] == 'stock_quantity') {
            objStockQuantity = $("#cblAttributeField").siblings("ul").children("li").eq(fieldIndex).children("a");
         }
      });
      //关联规格字段
      $("#cbIsSpec").on("click", function () {
         if ($(this).prop("checked") == true) {
            if (!objMarketPrice.parent().hasClass("selected")) {
               objMarketPrice.trigger("click");
            }
            if (!objSellPrice.parent().hasClass("selected")) {
               objSellPrice.trigger("click");
            }
            if (!objStockQuantity.parent().hasClass("selected")) {
               objStockQuantity.trigger("click");
            }
         }
      });
      objMarketPrice.on("click", function () {
         if (!$(this).parent().hasClass("selected") && $("#cbIsSpec").prop("checked") == true) {
            $("#cbIsSpec").trigger("click");
         }
      });
      objSellPrice.on("click", function () {
         if (!$(this).parent().hasClass("selected") && $("#cbIsSpec").prop("checked") == true) {
            $("#cbIsSpec").trigger("click");
         }
      });
      objStockQuantity.on("click", function () {
         if (!$(this).parent().hasClass("selected") && $("#cbIsSpec").prop("checked") == true) {
            $("#cbIsSpec").trigger("click");
         }
      });
      //设置焦点，防止JS无法提交
      $("#txtName").focus();
   });

   //创建窗口
   function showChannelDialog(obj) {
      var objNum = arguments.length;
      var d = top.dialog({
         id: 'dialogChannel',
         title: 'URL配置信息',
         url: '../dialog/dialog_channel/index'
      }).showModal();
      //检查是否修改状态
      if (objNum == 1) {
         d.data = obj;  // 给窗体传入对象
      }
   }

   //删除一行
   function delItemTr(obj) {
      top.dialog({
         title: '提示',
         content: '您确定要删除这个页面吗？',
         okValue: '确定',
         ok: function () {
            $(obj).parent().parent().remove(); //删除节点
         },
         cancelValue: '取消',
         cancel: function () { }
      }).showModal();
   }
</script>
}

<form id="from1" method="post" action="SubmitSave?action=@ViewBag.Action&id=@ViewBag.Id">
<!--导航栏-->
<div class="location">
  <a href="../channel_list/index" class="back"><i class="iconfont icon-up"></i><span>返回列表页</span></a>
  <a href="../../center/index"><i class="iconfont icon-home"></i><span>首页</span></a>
  <i class="arrow iconfont icon-arrow-right"></i>
  <a href="../channel_list/index"><span>频道管理</span></a>
  <i class="arrow iconfont icon-arrow-right"></i>
  <span>编辑频道</span>
  <div class="clipboard">
     <span><label id="clipMess"></label></span>
     <a href="javascript:;" class="copy" onclick="copy();"><i class="iconfont icon-copy"></i><span>复制</span></a>
     <a href="javascript:;" class="paste disable" onclick="paste();"><i class="iconfont icon-log"></i><span>粘贴</span></a>
  </div>
</div>
<div class="line10"></div>
<!--/导航栏-->

<!--内容-->
<div id="floatHead" class="content-tab-wrap">
  <div class="content-tab">
    <div class="content-tab-ul-wrap">
      <ul>
        <li><a class="selected" href="javascript:;">基本信息</a></li>
        <li><a href="javascript:;">URL配置</a></li>
      </ul>
    </div>
  </div>
</div>

<div class="tab-content">
  <dl>
    <dt>调用名称</dt>
    <dd>
      @if(ViewBag.Action as string == DTEnums.ActionEnum.Edit.ToString()){
         @Html.TextBox("txtName", m.name, new { @class="input normal", datatype=@"/^[a-zA-Z0-9\-\_]{2,50}$/", errormsg="请填写正确的名称！", sucmsg=" ", ajaxurl = "/tools/admin_ajax.ashx?action=channel_name_validate&old_channel_name=" + Utils.UrlEncode(m.name)})
      }
      else{
         @Html.TextBox("txtName", m.name, new { @class = "input normal", datatype = @"/^[a-zA-Z0-9\-\_]{2,50}$/", errormsg = "请填写正确的名称！", sucmsg = " " })
      }
      <span class="Validform_checktip">*调用名称，只允许使用英文、数字或下划线。</span>
    </dd>
  </dl>
  <dl>
    <dt>频道标题</dt>
    <dd>
      @Html.TextBox("txtTitle", m.title, new { @class="input normal", datatype="*2-100", sucmsg=" "})
      <span class="Validform_checktip">*标题备注，允许中文。</span></dd>
  </dl>
  <dl>
    <dt>所属站点</dt>
    <dd>
      <div class="rule-single-select">
        @Html.DropDownList("ddlSiteId", new SelectList( siteList, "Value", "Text", m.site_id), new { datatype="*", errormsg="请选择所属站点！", sucmsg=" " })
      </div>
    </dd>
  </dl>
  <dl>
    <dt>是否启用</dt>
    <dd>
      <div class="rule-single-checkbox">
         @Html.CheckBox("cbIsLock", m.is_lock == 0)
      </div>
      <span class="Validform_checktip">*是否启用该频道</span>
    </dd>
  </dl>
  <dl>
    <dt>开启评论</dt>
    <dd>
      <div class="rule-single-checkbox">
         @Html.CheckBox("cbIsComment", m.is_comment == 1)
      </div>
      <span class="Validform_checktip">*开启评论后用户可在评论文章</span>
    </dd>
  </dl>
  <dl>
    <dt>开启相册</dt>
    <dd>
      <div class="rule-single-checkbox">
         @Html.CheckBox("cbIsAlbums", m.is_albums == 1)
      </div>
      <span class="Validform_checktip">*开启相册功能后可上传多张图片</span>
    </dd>
  </dl>
  <dl>
    <dt>开启附件</dt>
    <dd>
      <div class="rule-single-checkbox">
         @Html.CheckBox("cbIsAttach", m.is_attach == 1)
      </div>
      <span class="Validform_checktip">*开启附件功能后可上传多个附件。</span>
    </dd>
  </dl>
  <dl>
    <dt>开启规格</dt>
    <dd>
      <div class="rule-single-checkbox">
         @Html.CheckBox("cbIsSpec", m.is_spec == 1)
      </div>
      <span class="Validform_checktip">*开启规格需选中市场价、销售价、库存三个扩展字段</span>
    </dd>
  </dl>
  <dl>
    <dt>排序数字</dt>
    <dd>
      @Html.TextBox("txtSortId", m.sort_id, new { @class="input small", datatype="n", sucmsg=" "})
      <span class="Validform_checktip">*数字，越小越向前</span>
    </dd>
  </dl>
  <dl>
    <dt>选择字段</dt>
    <dd>
      <div class="rule-multi-porp">
         <span id="cblAttributeField">
            @for(int i=0; i<fieldList.Rows.Count; i++) {
               DataRow dr = fieldList.Rows[i];
               if (m.channel_fields == null) {
                  @Html.CheckBox("cblAttributeField_" + i , false, new { value = dr["name"] + "," + dr["id"] })<label for="cblAttributeField_@i">@dr["title"]</label>
               }
               else{
                  @Html.CheckBox("cblAttributeField_" + i , m.channel_fields.Find(p => p.field_id == (int)dr["id"]) != null, new { value = dr["name"] + "," + dr["id"] })<label for="cblAttributeField_@i">@dr["title"]</label>
               }
            }
         </span>
      </div>
    </dd>
  </dl>
</div>

<div class="tab-content" style="display:none;">
  <dl>
    <dt>URL生成配置</dt>
    <dd><a id="itemAddButton" class="icon-btn add"><i class="iconfont icon-add"></i><span>添加页面</span></a></dd>
  </dl>
  <dl>
    <dt></dt>
    <dd>
      <div class="table-container">
          <table border="0" cellspacing="0" cellpadding="0" class="border-table" width="100%">
            <thead>
              <tr>
                <th width="12%">类型</th>
                <th width="16%">调用名称</th>
                <th width="25%">生成文件名</th>
                <th width="25%">模板文件名</th>
                <th width="12%">分页大小</th>
                <th width="10%">操作</th>
              </tr>
            </thead>
            <tbody id="item_box">
@foreach(DTcms.Model.url_rewrite item in urlList){
              <tr class="td_c">
                <td>
                  <input type="hidden" name="item_rewrite" value="@item.url_rewrite_str" />
                  <input type="hidden" name="item_type" value="@item.type" />
                  <span class="item_type">
                     @switch (item.type) {
                        case "index":
                           @:首页
                           break;
                        case "category":
                           @:栏目页
                           break;
                        case "list":
                           @:列表页
                           break;
                        case "detail":
                           @:详细页
                           break; 
                     }
                  </span>
                </td>
                <td>
                  <input type="hidden" name="old_item_name" value="@item.name" />
                  <input type="hidden" name="item_name" value="@item.name" />
                  <span class="item_name">@item.name</span>
                </td>
                <td>
                  <input type="hidden" name="item_page" value="@item.page" />
                  <span class="item_page">@item.page</span>
                </td>
                <td>
                  <input type="hidden" name="item_templet" value="@item.templet" />
                  <span class="item_templet">@item.templet</span>
                </td>
                <td>
                  <input type="hidden" name="item_pagesize" value="@item.pagesize" />
                  <span class="item_pagesize">@(item.pagesize != "" ? item.pagesize : "-")</span>
                </td>
                <td>
                  <a title="编辑" class="img-btn" onclick="showChannelDialog(this);"><i class="iconfont icon-edit"></i></a>
                  <a title="删除" class="img-btn" onclick="delItemTr(this);"><i  class="iconfont icon-delete"></i></a>
                </td>
              </tr>
}
            </tbody>
          </table>
      </div>
    </dd>
  </dl>
</div>
<!--/内容-->

<!--工具栏-->
<div class="page-footer">
  <div class="btn-wrap">
    <input type="submit" id="btnSubmit" class="btn" value="提交保存" />
    <input name="btnReturn" type="button" value="返回上一页" class="btn yellow" onclick="javascript:history.back(-1);" />
  </div>
</div>
<!--/工具栏-->
</form>
